{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 82,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2018-01-10T19:01:23.585000Z",
     "start_time": "2018-01-10T19:01:23.464000Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "   LocaleId  BirthYearInt  GenderId  JoinedYearMonth  TimezoneInt\n",
      "0  0.000020      0.000027  0.000019         0.000026     0.000036\n",
      "1  0.000020      0.000027  0.000019         0.000026     0.000031\n",
      "2  0.000028      0.000027  0.000019         0.000026    -0.000018\n",
      "3  0.000028      0.000027  0.000038         0.000027     0.000016\n",
      "4  0.000020      0.000027  0.000038         0.000026     0.000031\n",
      "<class 'pandas.core.frame.DataFrame'>\n",
      "RangeIndex: 38209 entries, 0 to 38208\n",
      "Data columns (total 5 columns):\n",
      "LocaleId           38209 non-null float64\n",
      "BirthYearInt       38209 non-null float64\n",
      "GenderId           38209 non-null float64\n",
      "JoinedYearMonth    38209 non-null float64\n",
      "TimezoneInt        38209 non-null float64\n",
      "dtypes: float64(5)\n",
      "memory usage: 1.5 MB\n",
      "None\n"
     ]
    }
   ],
   "source": [
    "import pandas as pd\n",
    "import numpy as np\n",
    "from sklearn.cluster import MiniBatchKMeans\n",
    "from sklearn import metrics\n",
    "import time\n",
    "\n",
    "import matplotlib.pyplot as plt\n",
    "%matplotlib inline\n",
    "\n",
    "\n",
    "data = pd.read_csv('users_FE.csv')\n",
    "data = data.drop([\"Unnamed: 0\"], axis=1)\n",
    "data = data.drop([\"cluster_100\"], axis=1)\n",
    "print data.head()\n",
    "print data.info()\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 83,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2018-01-10T19:01:24.401000Z",
     "start_time": "2018-01-10T19:01:24.388000Z"
    },
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "def K_minibatch_cluster(K,in_data,batchsize,reassignmentratio,ninit):\n",
    "    start =time.time()\n",
    "    print(\"miniBatchKMeans begin with clusters: {}\".format(K));\n",
    "    \n",
    "    miniKmean = MiniBatchKMeans(n_clusters=K,batch_size=batchsize,reassignment_ratio=reassignmentratio,n_init=ninit)\n",
    "    minifit = miniKmean.fit(in_data)\n",
    "    labels = minifit.labels_\n",
    "    CH_score = metrics.calinski_harabaz_score(in_data,labels)\n",
    "    end = time.time()\n",
    "    print(\"CH_score: {}, time elaps:{}\".format(CH_score, int(end-start)))\n",
    "\n",
    "    return CH_score,minifit"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 84,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2018-01-10T19:01:27.974000Z",
     "start_time": "2018-01-10T19:01:26.071000Z"
    },
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "miniBatchKMeans begin with clusters: 20\n",
      "CH_score: 42455.1540198, time elaps:0\n",
      "miniBatchKMeans begin with clusters: 40\n",
      "CH_score: 1.02257971286e+15, time elaps:0\n",
      "miniBatchKMeans begin with clusters: 80\n",
      "CH_score: 21851753.8545, time elaps:0\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "[<matplotlib.lines.Line2D at 0x163c9c88>]"
      ]
     },
     "execution_count": 84,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAXcAAAEDCAYAAADOc0QpAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDIuMS4wLCBo\ndHRwOi8vbWF0cGxvdGxpYi5vcmcvpW3flQAAIABJREFUeJzt3Xuc1nP+//HHq5mmqLZ0QCoVsgmL\nNXL81VQO1aasU7EsFlnWYh1D54ScDxtbyGFJkhCb0tn5MJFI+kqsklVOOTel9++P19U2O6bmarpm\n3tfheb/dujXXdX2m6/Vprus57+v9eR8shICIiGSXGrELEBGR1FO4i4hkIYW7iEgWUriLiGQhh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22zo370C73cfD+yI/wceF0L4MkqRSTKz3wD3\n41fMawDjQwhDzWwnvAXcEHgTOCmEsDpepckzsyLg4hBCj0w8j0TNjydu5gNjQwjDzawRGfb6AjCz\nvYG7gQJgCXAaidcaGXQuZrY1fiFypxDCqsR9mfozGQL0xkf+vQmcgfexV+l7Je3DXURENl/ad8uI\niMjmU7iLiGQhhbuISBZSuIuIZCGFu4hIFlK4i4hkIYW7iEgW+v/Xcvl18brQfgAAAABJRU5ErkJg\ngg==\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0x1616d2b0>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "Ks = [20,40,80]\n",
    "batchsize = 150 #100,120\n",
    "reassignmentratio = 0.008 #0.01,0.005\n",
    "ninit = 5\n",
    "CH_scores = []\n",
    "df_FE = data\n",
    "for K in Ks:\n",
    "    ch,mini_fit = K_minibatch_cluster(K,data,batchsize,reassignmentratio,ninit)\n",
    "    CH_scores.append(ch)\n",
    "    cluster_ = 'cluster_' + str(K)\n",
    "    df_FE['cluster_'] = mini_fit.predict(data)\n",
    "    users_cluster_XX = 'users_cluster_' + str(K) + '.csv'\n",
    "#     df_FE.to_csv('users_cluster_XX.csv')\n",
    "    df_FE.to_csv(users_cluster_XX)\n",
    "    df_FE.head()\n",
    "plt.plot(Ks,np.array(CH_scores),'b-')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python [default]",
   "language": "python",
   "name": "python2"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.14"
  },
  "toc": {
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": true,
   "toc_window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
